#include "business.h"
#include "ui_business.h"
#include "widget.h"
#include<iostream>
#include<fstream>
#include <QDebug>
#include <QTreeWidgetItem>
#include <QKeyEvent>
#include<QFile>
#include<QTableWidget>
#include<QCoreApplication>
#include<QCheckBox>
#include<QFileDialog>
#include<QMessageBox>
#include<QSpinBox>
#include<QWidget>
#include "string.h"
#include "client.h"
#include "./poco/order.h"
#include"submitorder.h"

//#include"QNetworkAccessManager.h"
#include"poco/saleBase.h"

#include"add_dish.h"
using namespace std;
business::business(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::business)
{
    ui->setupUi(this);
    ui->stackedWidget->setCurrentIndex(4);
}

business::~business()
{
    delete ui;
}
//设置商家信息
void business::set_inform(QString id,QString name){
    this->id=id.toInt();
    this->name=name;
    ui->name_label->setText(this->name);
}
//界面美化
void business::keyPressEvent(QKeyEvent *event)
{
    if(event->key()==Qt::Key_F11)
    {
    QFile f;
    auto str=QCoreApplication::applicationDirPath();
    f.setFileName(str+"//"+"stuqss.css");
    f.open(QIODevice::ReadOnly);
    QString str1 =f.readAll();
    this->setStyleSheet(str1);
    }
}



//点餐界面
void business::show_dish(){
    /*在这里显示主窗口的菜单
     * todo:
     * 先获取到当前窗口可以售卖的所有商品 controller
     *
     *
    */
    ui->dish_info->verticalHeader()->setDefaultSectionSize(100);
    WindowInfo _win_info = this->cur_win_info;
    //先打开window 获取一个 window ontroller
    this->merCon.openWindow(_win_info,this->winCon); // get winCon
    // 然后 通过win controller 获得售卖的商品的信息
    // todo getSales 无法获取信息 ？？？
    this-> _sale_vec = this->winCon.getSales();

    //遍历所有的信息 并依次处理
    //for(int i=0;i<_sale_vec.size();i++)
    for(SaleBase *_cur_meal : _sale_vec)
    {
        //SaleBase *_cur_meal = _sale_vec[i]; //int status;//食物状态 0：售卖中 1：停售 2：审批中
        if(_cur_meal->status != SaleBase::STATUS_onSale) //!售卖中
            continue;
        // 注意 class_type 对应 saleunit里面的type字段
        //食物类型: 单品售卖:1，重量售卖:2，套餐售卖:3，配菜:4
        dish_picture.push_back(_cur_meal->image);
        dish_name.append(QString::fromStdString(_cur_meal->name));
        dish_type.append(QString::fromStdString(_cur_meal->diningType));
        dish_price.append(QString::number(_cur_meal->price,'f',2));
        dish_unit.append(QString::fromStdString(_cur_meal->unit));
        dish_description.append(QString::fromStdString(_cur_meal->desciption));
        dish_status.push_back(_cur_meal->class_type);
    }


    ui->dish_info->horizontalHeader()->setStretchLastSection(true); //设置表头充满表格的宽度
    ui->dish_info->setRowCount(dish_picture.size());
        for(int row=0;row<=dish_picture.size()-1;row++)
        {

            QLabel *l1 = new QLabel();     //创建lable
            QPixmap pixmap(dish_picture[row]);
            pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
            l1->setPixmap(pixmap);    //加载图片
            l1->setAlignment(Qt::AlignHCenter);      //设置居中
/*            ui->dish_info->setCellWidget(row,0,l1);    */ //显示
            QHBoxLayout *layout1=new QHBoxLayout();
            QWidget *widget_lb1=new QWidget();
            layout1->addWidget(l1);
            widget_lb1->setLayout(layout1);
            ui->dish_info->setCellWidget(row,0,widget_lb1);

            ui->dish_info->setItem(row,1,new QTableWidgetItem(dish_description[row]));
            ui->dish_info->setItem(row,2,new QTableWidgetItem(dish_type[row]));
            ui->dish_info->setItem(row,3,new QTableWidgetItem(dish_unit[row]));
            ui->dish_info->setItem(row,4,new QTableWidgetItem(dish_price[row]));
            // 新建一个按钮
            //食物类型: 单品售卖:1，重量售卖:2    ，套餐售卖:3，    配菜:4
            qDebug()<<dish_type[row];
            if(dish_status[row]== 3){
                qDebug()<<"当前菜品的类型为组合";
                QHBoxLayout *layout=new QHBoxLayout();
                QPushButton*button = new QPushButton();
                button->setFixedSize(70,30);
                button->setText("选套餐");
                connect(button, SIGNAL(clicked()), this, SLOT(slotbuttonClicked()));
                QWidget *widget_lb=new QWidget();
                layout->addWidget(button);
                widget_lb->setLayout(layout);
                ui->dish_info->setCellWidget(row,5,widget_lb);
            }
            // 调用接口将按钮插入到QTableWidget指定的行列中
            else if(dish_status[row]== 1 || dish_status[row]== 2){
                qDebug()<<"当前菜品的类型为组合";
                QHBoxLayout *layout=new QHBoxLayout();
                QPushButton*button = new QPushButton();
                button->setFixedSize(70,30);
                button->setText("添加");
                connect(button, SIGNAL(clicked()), this, SLOT(slotbuttonClicked1()));
                QWidget *widget_lb=new QWidget();
                layout->addWidget(button);
                widget_lb->setLayout(layout);
                ui->dish_info->setCellWidget(row,5,widget_lb);
            widget_lb->setLayout(layout);
            ui->dish_info->setCellWidget(row,5,widget_lb);
            }
            else if(dish_status[row]== 4){
            //配菜只能看 不能操作
            QLabel * label=new QLabel();
            label->setText(QString("只能看，不能选"));

            ui->dish_info->setCellWidget(row,5,label);

            }else{
                qDebug()<<"当前菜品的类型 error !!!!!" << dish_status[row];
                return;
            }


}
        //button->setIcon(QPixmap("D:/canteen-management-system1/shitang.jpg"));


}
//点击打开窗口
void business::on_open_Button_clicked()
{
    qDebug()<<QString("点击打开窗口按钮");
    ui->stackedWidget->setCurrentIndex(4);
    ui->open_Button->setStyleSheet("background-color: green");
    ui->add_window_Button->setStyleSheet("background-color: #34495E");
    ui->add_dish_Button->setStyleSheet("background-color: #34495E");
    ui->join_Button->setStyleSheet("background-color: #34495E");
    //创建新窗口
    new_win_choose();

}
void business::new_win_choose(){

    widget =new QWidget(NULL);
    widget->setWindowModality(Qt::NonModal);
    widget->setWindowTitle(tr("请选择需要开启的窗口"));
    widget->resize(600,900);
    table=new QTableWidget(widget);
    table->clear();

    QStringList header;
    header<<"窗口名称"<<"窗口地址"<<"勾选框";
    table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    table->setGeometry(50,80,500,600);
    table->setColumnCount(header.size());
    //设置行高
    table->setRowHeight(0,130);

    table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    //    table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
//     table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
    table->setColumnWidth(0,240);
    table->setColumnWidth(1,240);
    //将默认序号隐藏
    table->verticalHeader()->hide();
    //添加表头
    table->setHorizontalHeaderLabels(header);
    //表头信息居中
    table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
    //设置最后一行自适应
    table->horizontalHeader()->setStretchLastSection(true);
    //选取一整行
    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    //单行选中
    table->setSelectionMode(QAbstractItemView::SingleSelection);
    //不可编辑
    table->setEditTriggers(QAbstractItemView::NoEditTriggers);
    //隔行变色
    table->setAlternatingRowColors(true);
    table->setStyleSheet("QHeaderView::section{background-color:rgb(227, 247, 255);border:1px solid black;}");

//    table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
//    table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);

    /*
    * edit by cheney
    */
    // 先定义一个数组，用来存储所有的 window的信息
    // vector<WindowInfo> _win_info_list;
    // 然后调用商家controller 填充这个数组
    this -> merCon.getWindows(_win_info_list);
    qDebug()<<QString("当前可选择开的窗口有")<<_win_info_list.size()<<QString("个");
     table->setRowCount(_win_info_list.size());
    for(int i = 0; i < _win_info_list.size(); i++){
        WindowInfo _win_cur = _win_info_list[i];
        this -> cur_win_info = _win_cur; //将获取到的 要打开的窗口 储存起来
        qDebug()<<QString("窗口")<<i<<QString("的状态为")<<_win_cur.status;
        if(_win_cur.status == WindowInfo::STATUS_haltSale){
            qDebug()<<i<<QString("窗口正在审核");
          qDebug()<<QString::fromStdString(_win_cur.name)<<QString::fromStdString(_win_cur.address);
         table->setItem(i,0,new QTableWidgetItem(QString::fromStdString(_win_cur.name)));
         table->setItem(i,1,new QTableWidgetItem(QString::fromStdString(_win_cur.address)));
         table->setItem(i,2,new QTableWidgetItem(QString::fromStdString("窗口正在审核")));
         table->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
         table->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
         table->item(i,2)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        }
            // todo：dao操作有误，不应该返回未营业状态的info，改完删除这两行
        else if (_win_cur.status == WindowInfo::STATUS_failture){
             qDebug()<<i<<QString("窗口审核未通过");
            QLabel * label=new QLabel();
            label->setText(QString("窗口审核未通过"));
          qDebug()<<QString::fromStdString(_win_cur.name)<<QString::fromStdString(_win_cur.address);
         table->setItem(i,0,new QTableWidgetItem(QString::fromStdString(_win_cur.name)));
         table->setItem(i,1,new QTableWidgetItem(QString::fromStdString(_win_cur.address)));

          table->setCellWidget(i,2,label);
          table->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
          table->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
          //table->item(i,2)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);

        }
        else{
             qDebug()<<i<<QString("窗口可以开");
        qDebug()<<QString("插入行：")<<i;
         qDebug()<<QString::fromStdString(_win_cur.name)<<QString::fromStdString(_win_cur.address);
        QTableWidgetItem *check = new QTableWidgetItem();
        check->setCheckState(Qt::Unchecked);
        table->setItem(i,0,new QTableWidgetItem(QString::fromStdString(_win_cur.name)));
        table->setItem(i,1,new QTableWidgetItem(QString::fromStdString(_win_cur.address)));
        table->setItem(i,2,check);
        table->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        table->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        }
    }

    QLabel *label=new QLabel(widget);
    label->setGeometry(20,20,200,50);
    label->setStyleSheet("color:black;font:16px;");
    label->setText(tr("请选择需要开启的窗口"));

    QPushButton *chbtn=new QPushButton(widget);
    chbtn->setGeometry(20,800,200,50);
    chbtn->setText("确定");
    //connect(chbtn, SIGNAL(clicked()), this, SLOT(window_clicked(widget,table)));
    connect(chbtn, SIGNAL(clicked()), this, SLOT(window_clicked()));
    widget->show();
}

void business::window_clicked(){
    qDebug()<<QString("点击选择窗口按钮");
    QString win_name;
    qDebug()<<_win_info_list.size();
    for(int i=0;i< _win_info_list.size();i++){
       if(table->item(i,2)->checkState()){
           qDebug()<< QString("当前选择了第")<<i<<QString("行");
           win_name.append(table->item(i,0)->text());
           QTableWidgetItem *check = new QTableWidgetItem();
           check->setCheckState(Qt::Unchecked);
           table->setItem(i,2,check);
           this->cur_win_info = _win_info_list[i];  // 存储当前被选择的窗口info 到全局
           break; //这里要 break
       }
    }
    qDebug()<<"开启窗口为:"<<win_name<<"编号:"<<this->cur_win_info.id;
    // 添加其他响应信息......
    widget->close();
    ui->stackedWidget->setCurrentIndex(0);

    this->show_dish();



}
void business::slotbuttonClicked1(){
    qDebug()<<QString("用户选择了单品");
    // 获取当前被点击的按钮
    QPushButton* pSenderObj = qobject_cast<QPushButton*>(sender());
    if (pSenderObj == nullptr)
    {
        return;
    }
    QModelIndex qIndex = ui->dish_info->indexAt(QPoint(pSenderObj->frameGeometry().x(), pSenderObj->frameGeometry().y()));

    // 获取当前按钮所在的行和列
    int x = pSenderObj->parentWidget()->pos().x();
    int y=pSenderObj->parentWidget()->pos().y();
    QModelIndex index=ui->dish_info->indexAt(QPoint(x,y));
    int row=index.row();
    int column=index.column();
    qDebug()<<QString("用户点击了第")<<row<<QString("行，第")<<column<<QString("列");


    winCon.addSelectSale(winCon.getSales()[row]);//添加到订单中


    showOrder_detail();
//    int irow=ui->order_show->rowCount();


}

//点餐
void business::slotbuttonClicked()
{
    qDebug()<<QString("用户选择了组合");
    // 获取当前被点击的按钮
    QPushButton* pSenderObj = qobject_cast<QPushButton*>(sender());
    if (pSenderObj == nullptr)
    {
        return;
    }
    QModelIndex qIndex = ui->dish_info->indexAt(QPoint(pSenderObj->frameGeometry().x(), pSenderObj->frameGeometry().y()));

    // 获取当前按钮所在的行和列
    int x = pSenderObj->parentWidget()->pos().x();
    int y=pSenderObj->parentWidget()->pos().y();
    QModelIndex index=ui->dish_info->indexAt(QPoint(x,y));
    int row=index.row();
    int column=index.column();
    qDebug()<<QString("用户点击了第")<<row<<QString("行，第")<<column<<QString("列");
    QMessageBox::information(this,tr("success"),tr("点套餐，显示下一个窗口"),QMessageBox::Yes);

    //套餐窗口
    SaleSetMeal* setMeal=(SaleSetMeal*)this->_sale_vec[row];
    client *taocan=new client();
    taocan->setWindowTitle(QString::fromStdString(setMeal->name));//窗口名称
    taocan->resize(QSize(1000,1000));

    taocan->setSales(setMeal);//传数据
    taocan->init();

    // 添加其他响应信息......
//    SaleSetMeal* _set_food_in = (SaleSetMeal*) this-> _sale_vec[row];
//    taocan->nums = _set_food_in -> nums;
//    taocan->foodTypes = _set_food_in->foodTypes;

    //食物传输，套餐选择界面传输

    taocan->show();
    winCon.addSelectSale(setMeal);
    //右侧订单显示
     showOrder_detail();
}



void business::dish_cancel_clicked(){
    qDebug()<<QString("用户选择了取消");
    // 获取当前被点击的按钮
    QPushButton* pSenderObj1 = qobject_cast<QPushButton*>(sender());
    if (pSenderObj1 == nullptr)
    {
        return;
    }
    QModelIndex qIndex1 = ui->order_show->indexAt(QPoint(pSenderObj1->frameGeometry().x(), pSenderObj1->frameGeometry().y()));

    // 获取当前按钮所在的行和列
    int x = pSenderObj1->parentWidget()->pos().x();
    int y=pSenderObj1->parentWidget()->pos().y();
    QModelIndex index1=ui->order_show->indexAt(QPoint(x,y));
    int row=index1.row();
    int column=index1.column();
    qDebug()<<QString("用户点击了第")<<row<<QString("行，第")<<column<<QString("列");

    winCon.delSelectSale(row);//删除
    showOrder_detail();
}

 void business::showOrder_detail()
 {
     //右侧订单显示
      ui->order_show->verticalHeader ()->setDefaultSectionSize (50) ;
     int irow=winCon.getOrder().sales.size();//显示的数据数
      ui->order_show->setRowCount(irow);
     for(int i=0;i<irow;i++)
     {
         ui->order_show->setItem(i,0,new QTableWidgetItem( QString ::number(i+1,10)));
         ui->order_show->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
         ui->order_show->setItem(i,1,new QTableWidgetItem(QString::fromStdString(winCon.getOrder().sales[i]->name)));
         ui->order_show->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
         qDebug()<<"当前菜品的类型为单品";

         QHBoxLayout *layout=new QHBoxLayout();
         QPushButton*button = new QPushButton();
         button->setFixedSize(70,30);
         button->setText("取消");
         connect(button, SIGNAL(clicked()), this, SLOT(dish_cancel_clicked()));
         QWidget *widget_lb=new QWidget();
         layout->addWidget(button);
         widget_lb->setLayout(layout);
         ui->order_show->setCellWidget(i,2,widget_lb);
     }
 }



























//点击添加菜品
void business::on_add_dish_Button_clicked()
{
    qDebug()<<QString("点击添加菜品按钮");
    ui->stackedWidget->setCurrentIndex(1);
    ui->open_Button->setStyleSheet("background-color: #34495E");
    ui->add_window_Button->setStyleSheet("background-color: #34495E");
    ui->add_dish_Button->setStyleSheet("background-color: green");
    ui->join_Button->setStyleSheet("background-color: #34495E");
}












void business::cur_organ_show(){
    QStringList strHeader;
        //设置表头 勾选 << 服务器地址 << 数据库类型 << 数据库名称 << 用户名
    strHeader << "勾选框" << "组织名称" << "组织地址" ;
    ui->tableWidget->setHorizontalHeaderLabels(strHeader);

    cur_organ.append("学一一楼三号");
    cur_organ.append("学一一楼四号");
    cur_organ.append("学一三楼中央");
    cur_organ.append("学一二楼四号");
    cur_organ.append("学一三楼四号");
    qDebug()<<cur_organ;
    //加盟申请，查询组织
    vector<OrganizationInfo> vct_org;
    merCon.getAllOrg(vct_org);
    vct_org_apply=vct_org;
    int iRow = vct_org.size();
    qDebug()<<QString("有")<<iRow<<QString("行");
    ui->tableWidget_2->setRowCount(iRow);
    for(int row=0;row<iRow;row++)
    {
    qDebug()<<QString("插入行：")<<row;
    QTableWidgetItem *check = new QTableWidgetItem();
    check->setCheckState(Qt::Unchecked);
    ui->tableWidget_2->setItem(row,0,check);
    ui->tableWidget_2->setItem(row,1,new QTableWidgetItem(QString::fromStdString(vct_org[row].name)));
    ui->tableWidget_2->setItem(row,2,new QTableWidgetItem(QString::fromStdString(vct_org[row].address)));
    }
}
void business::cur_organ_show1(){
    qDebug()<<QString("再次显示");
    QStringList strHeader;
        //设置表头 勾选 << 服务器地址 << 数据库类型 << 数据库名称 << 用户名
    strHeader << "勾选框" << "组织名称" << "组织地址" ;
    ui->tableWidget->setHorizontalHeaderLabels(strHeader);
    qDebug()<<cur_organ;
    int iRow = cur_organ.size()-1;
    qDebug()<<QString("有")<<iRow<<QString("行");
    ui->tableWidget_2->setRowCount(iRow);
    for(int row=0;row<=iRow;row++)
    {
    qDebug()<<QString("插入行：")<<row;
    QTableWidgetItem *check = new QTableWidgetItem();
    check->setCheckState(Qt::Unchecked);
    ui->tableWidget_2->setItem(row,0,check);
    ui->tableWidget_2->setItem(row,1,new QTableWidgetItem(cur_organ[row]));
    ui->tableWidget_2->setItem(row,2,new QTableWidgetItem("lalalla"));
    }
}
//点击加盟申请
void business::on_join_Button_clicked()
{
    qDebug()<<QString("点击加盟申请按钮");
    ui->stackedWidget->setCurrentIndex(3);
    ui->open_Button->setStyleSheet("background-color: #34495E");
    ui->add_window_Button->setStyleSheet("background-color: #34495E");
    ui->add_dish_Button->setStyleSheet("background-color: #34495E");
    ui->join_Button->setStyleSheet("background-color: green");
    //获取勾选的组织
    cur_organ_show();
}
//点击加入组织
void business::on_pushButton_4_clicked()
{
    qDebug()<<QString("商家点击加盟组织");
    qDebug()<<QString("当前可选组织数量为:")<<cur_organ.size();
    for(unsigned int i=0;i<vct_org_apply.size();i++){
       if(ui->tableWidget_2->item(i,0)->checkState()){
           //进行申请
            merCon.joinOrg(vct_org_apply[i]);

           qDebug()<< QString("当前选择了第")<<i<<QString("行");
           qDebug()<< QString("商家选择了")<<ui->tableWidget_2->item(i,1)->text()<<QString("组织");
           apply_organ.append(ui->tableWidget_2->item(i,1)->text());
           qDebug()<<QString("申请组织名称已添加");
           cur_organ.removeAt(i);
           qDebug()<<QString("组织名称已删除");
       }
    }
    cur_organ_show();//视图刷新
    qDebug()<<QString("申请的窗口为:")<<apply_organ;
     QMessageBox::information(this,tr("success"),tr("加盟组织已申请"),QMessageBox::Yes);
}



























//添加菜品确定
void business::on_pushButton_clicked()
{
//    //    int id;//食物id
//    int window_id;//所属窗口id
//    int status;

    //食物名称string name

    QString str1=ui->lineEdit->text();
    qDebug()<<QString("食物名称为:")<<str1;
    std::string name = str1.toStdString();
    //食物单价double price
    double price;
    str1=ui->lineEdit_3->text();
    qDebug()<<QString("食物单价为:")<<str1;
    price=str1.toDouble();
    //食物状态int status//食物状态 0：售卖中 1：停售 2：审批中

    //餐饮类型string diningType
    str1=ui->dingingType->currentText();
    qDebug()<<QString("食物类型为:")<<str1;
    std::string diningType=str1.toStdString();
    //食物单位string unit
    str1=ui->unit->text();
    qDebug()<<QString("食物单位为:")<<str1;
    std::string unit=str1.toStdString();
    //食物图片QImage image
    //食物描述string description
    str1=ui->description->toPlainText();
    qDebug()<<QString("食物描述为:")<<str1;
    std::string description=str1.toStdString();

    QMessageBox::information(this,tr("success"),tr("提交完成"),QMessageBox::Yes);
}

//点击添加图片按钮
void business::on_pushButton_2_clicked()
{

    QString path = QFileDialog::getOpenFileName(this, tr("选择图片"), ".", tr("Image Files(*.jpg *.png)"));
    QImage* img = new QImage;

    if(!(img->load(path))) //加载图像
    {
       QMessageBox::information(this, tr("打开图像失败"), tr("打开图像失败!"));
       delete img;
       return;
    }

    img->scaled(ui->label_picture->size(), Qt::KeepAspectRatio);
    ui->label_picture->setScaledContents(true);
    ui->label_picture->setPixmap(QPixmap::fromImage(*img));

}

//选择按钮为组合
void business::on_dingingType_activated(int index)
{

//    int id;//食物id
//    int window_id;//所属窗口id
//    string name;//食物名称
//    double price;//食物单价
//    int status;//食物状态 0：售卖中 1：停售 2：审批中
//    string diningType;//餐饮类型
//    string unit;//食物单位
//    QImage image;//食物图片
//    string desciption;//食物描述
    qDebug()<<QString("添加组合");
    if(index==2){
          QStringList name1={"猪肉","牛肉","鸡肉","豆角","豆腐"};
          add_dish *dish=new add_dish();
          dish->set_inform(name1,this->id);
          dish->show();

      }
}



//点击添加窗口

void business::on_add_window_Button_clicked()
{
    qDebug()<<QString("点击添加窗口按钮");
    ui->stackedWidget->setCurrentIndex(2);
    ui->open_Button->setStyleSheet("background-color: #34495E");
    ui->add_window_Button->setStyleSheet("background-color: green");
    ui->add_dish_Button->setStyleSheet("background-color: #34495E");
    ui->join_Button->setStyleSheet("background-color: #34495E");
    cur_window_show();
}

void business::cur_window_show(){
    QStringList strHeader;
        //设置表头 勾选 << 服务器地址 << 数据库类型 << 数据库名称 << 用户名
    strHeader << "勾选框" << "窗口地址" << "收租方式" ;
    ui->tableWidget->setHorizontalHeaderLabels(strHeader);

    cur_window.append("学一一楼三号");
    cur_window.append("学一一楼四号");
    cur_window.append("学一三楼中央");
    cur_window.append("学一二楼四号");
    cur_window.append("学一三楼四号");
    qDebug()<<cur_window;

    vector<WindowInfo> vct_win;
    //获取可申请的窗口
    merCon.getApplyWindow(vct_win);
    vct_win_alpply=vct_win;
    int iRow = vct_win.size();
    qDebug()<<QString("有")<<iRow<<QString("行");
    ui->tableWidget->setRowCount(iRow);
    for(int row=0;row<iRow;row++)
    {
    qDebug()<<QString("插入行：")<<row;
    QTableWidgetItem *check = new QTableWidgetItem();
    check->setCheckState(Qt::Unchecked);
    ui->tableWidget->setItem(row,0,check);
    ui->tableWidget->setItem(row,1,new QTableWidgetItem(QString::fromStdString(vct_win[row].address)));
    ui->tableWidget->setItem(row,2,new QTableWidgetItem("日租"));
    }
}

void business::cur_window_show1(){
    QStringList strHeader;
        //设置表头 勾选 << 服务器地址 << 数据库类型 << 数据库名称 << 用户名
    strHeader << "勾选框" << "窗口地址" << "收租方式" ;
    ui->tableWidget->setHorizontalHeaderLabels(strHeader);

    qDebug()<<cur_window;
    int iRow = cur_window.size()-1;
    qDebug()<<QString("有")<<iRow<<QString("行");
    ui->tableWidget->setRowCount(iRow);
    for(int row=0;row<=iRow;row++)
    {
    qDebug()<<QString("插入行：")<<row;
    QTableWidgetItem *check = new QTableWidgetItem();
    check->setCheckState(Qt::Unchecked);
    ui->tableWidget->setItem(row,0,check);
    ui->tableWidget->setItem(row,1,new QTableWidgetItem(cur_window[row]));
    }
}
//商家点击申请窗口
void business::on_pushButton_3_clicked()
{

    qDebug()<<QString("商家点击申请窗口");
    qDebug()<<QString("当前可选窗口数量为:")<<cur_window.size();
    for(unsigned int i=0;i<vct_win_alpply.size();i++){
       if(ui->tableWidget->item(i,0)->checkState()){
           //进行申请
            merCon.applyWindow(vct_win_alpply[i]);
            //
           qDebug()<< QString("当前选择了第")<<i<<QString("行");
           qDebug()<< QString("商家选择了")<<ui->tableWidget->item(i,1)->text()<<QString("窗口");
           apply_window.append(ui->tableWidget->item(i,1)->text());
           window_name.append(ui->window_name->text());
           cur_window.removeAt(i);
       }
    }

    cur_window_show();//刷新视图
    qDebug()<<QString("申请的窗口为:")<<apply_window<<QString("窗口的名称为")<<window_name;
     QMessageBox::information(this,tr("success"),tr("添加窗口已申请"),QMessageBox::Yes);
}


//点击提交按钮
void business::on_submid_clicked()
{
    QMessageBox::information(this,tr("success"),tr("提交订单"),QMessageBox::Yes);
//    order *submit_order=new order();
//    submit_order->show();
    SubmitOrder* sub=new SubmitOrder;
    sub->setWindowController(&winCon);
    sub->show();
    connect(sub,SIGNAL(checkOnOver()),this,SLOT(showOrder_detail()));
}



//添加折扣按钮
void business::on_join_Button_2_clicked()
{
  ui->stackedWidget->setCurrentIndex(5);
}

//点击打折完成按钮
void business::on_pushButton_5_clicked()
{
    QString discount_name=ui->discount_name->currentText();
    int discount_price=ui->discount_price->value();
    qDebug()<<QString("选择的折扣方式为:")<<discount_name<<QString("折扣价格为:")<<discount_price;
    QMessageBox::information(this,tr("success"),tr("添加折扣成功"),QMessageBox::Yes);
    ui->discount_price->setValue(0);
}


void business::order_show(){

}


